<?php namespace Admin\Controller;
/*
 * 类型控制器
 * */
 	class TypeController extends  CommonController
 	{
 		public $type; //实例化类型表
		public $attribute;//实例化属性
		public function __init(){
			$this->type = new \Common\Model\type;
			$this->attribute = new \Common\Model\typeattribute;
		}
		/*
		 * 首页
		 * */
 		public function index()
 		{
 			$data = $this->type->get();
			View::with("data",$data);
 			View::make();
 		}
		/*
		 * 添加类别
		 * */
		public function addType()
		{
			if(IS_POST){
				if(!$this->type->addtype()){
					View::error($this->type->getError());
				}else{
					View::success("添加成功",U('index'));
				}
			}
			
			View::make();
		}
		
		/*
		 * 属性
		 * */
		public function Attribute(){
			$id = Q("get.tid",0,"intval");
			$data = $this->attribute->where("type_tid",$id)->get();
			//p($data);die;
			View::with("data",$data);
			View::make();
		}
		/*
		 * 添加属性
		 * */
		public function addAttribute()
		{
			if(IS_POST){
				if(!$this->attribute->addAttribute()){
					View::error($this->type->getError());
				}else{
					View::success("添加成功",U('Attribute',array('tid'=>$_POST['type_tid'])));
				}
			}
			View::make();
		}
		
 	}
